package com.hbmcc.heshenghuo.util

import androidx.databinding.BindingAdapter
import android.graphics.Bitmap
import android.widget.ImageView
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.Glide
import com.hbmcc.heshenghuo.R

object ImageViewAttrAdapter {
    @JvmStatic
    @BindingAdapter("android:src")
    fun setSrc(view: ImageView, bitmap: Bitmap?) {
        view.setImageBitmap(bitmap)
    }

    @JvmStatic
    @BindingAdapter("android:src")
    fun setSrc(view: ImageView, resId: Int) {
        view.setImageResource(resId)
    }

    @JvmStatic
    @BindingAdapter("imageUrl")
    fun loadImage(imageView: ImageView, url: String?) {
        val options = RequestOptions().placeholder(R.mipmap.floor_default) //图片加载出来前，显示的图片
            .fallback(R.mipmap.floor_default) //url为空的时候,显示的图片
            .error(R.mipmap.floor_default)
        Glide.with(imageView.context).load(url).apply(options).into(imageView)
    }

    @JvmStatic
    @BindingAdapter("imgSelect")
    fun imgSelect(imageView: ImageView, isSelect: Boolean) {
        imageView.isSelected = isSelect
    }
}